<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-预警设置</title>
    <script src="/scripts/boot.js"></script>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>预警设置</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg"><span class="color-red">*</span>工期大于等于</td>
            <td>
                <input name="workDayLeast" id="workDayLeast" class="mini-spinner w250" value="1" minValue="0" maxValue="999" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/><span class="unit-span">%</span>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>工期小于</td>
            <td>
                <input name="workDayMax" class="mini-spinner w250" value="2" minValue="1" maxValue="10000" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/><span class="unit-span">%</span>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg">
                <span class="color-red">*</span>状态
            </td>
            <td>
                <select id="status" name="status" class="mini-combobox w250" ajaxType="post" data="[{ id: '1', value: '有风险' }]" textField="value" valueField="id"  errorMode="none" onvalidation="onChoseValidation" required="true" requiredErrorText="请选择"></select>
            </td>
            <td class="text-titlebg"><span class="color-red">*</span>进度小于</td>
            <td>
                <input name="schedule" class="mini-spinner w250" value="" minValue="1" maxValue="100" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"/><span class="unit-span">%</span>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">说明</td>
            <td colspan="3" class="wp">
            	<input type="hidden" class="mini-hidden" name="id"/>
                <textarea name="remark" class="mini-textarea wtextarea" emptyText="" errorMode="none"  maxLength="240"></textarea>
            </td>
        </tr>
    </table>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<script type="text/javascript">
var post_flag,form,state,datas,msgState;
var view = {
    init: function () {
        post_flag = false; //设置一个对象来控制是否进入AJAX过程
        mini.parse();
        form = new mini.Form("#viewForm");
    },
    //保存
    save: function () {
        form.validate();
        if (form.isValid() == false) return;
        if (post_flag) return;
        var data = form.getData();//获取表单多个控件的数据
        if(data.workDayLeast>=data.workDayMax){ 
            mini.alert("工期小于'值'不能小于"+mini.get("workDayLeast").getValue());
            return
        }
        post_flag = true;
        $.ajax({
            url: (state=="new"?"/EarlyWarning/save":"/EarlyWarning/edit?id=" + data.id),
            type: "post",
            data: data,
            success: function (data) {
            	if(!data.state){
                    post_flag = false;
                    mini.alert(data.message);
            	}else{
                    CloseWindow("ok");
            	}
            },
            error: function (errorMsg) {
                post_flag = false;
                var msg  = JSON.parse(errorMsg.responseText);
                common.prompt(msg.message);
            }
        });
    },
//    数据展示
    SetData: function (data) {
        data = mini.clone(data);
        state = data.state;
        if(data.state=="edit"){
	        $.ajax({
	            url:"/EarlyWarning/info?id=" + data.id,
	            type: "post",
	            success: function (text) {
	                //跨页面传递的数据对象，克隆后才可以安全使用
	                datas = mini.decode(text);   //反序列化成对象
	                form.setData(datas);             //设置多个控件数据
                    mini.get("status").setValue(datas.status);
	            }
	        });
        }else{
        	$('input[name=id]').val("");
        }
    }
};
view.init();
</script>
</body>
</html>